from datetime import datetime, date, time, timedelta

# 获起当前时间
now = datetime.now()
print("now===", now)
print("格式化===", now.strftime("%Y-%m-%d"))
print("格式化===", now.strftime("%Y-%m-%d %H:%M:%S"))


# 创建特定时间
dt = datetime(2024, 1, 15, 14, 30, 0)
print("特定时间:", dt)


# 时间加减
tomorrow = now + timedelta(days=1)
last_week = now - timedelta(weeks=1)
print("明天:", tomorrow)
print("上周:", last_week)

# 时间差计算
time_diff = tomorrow - now
print("时间差:", time_diff)
print("相差天数:", time_diff.days)
print("相差秒数:", time_diff.total_seconds())


# 获取时间各部分
print("年:", now.year)
print("月:", now.month)
print("日:", now.day)
print("时:", now.hour)
print("分:", now.minute)
print("星期:", now.weekday())


# 字符串解析为时间对象
date_str = "2024-01-15 14:30:00"
parsed_date = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
print("解析后的时间:", parsed_date)


# time
print(time())
